Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Coffee Cup Image with Parallax Effect #54

Closed
wants to merge 2 commits into from

Conversation

anshi05
Copy link

@anshi05 anshi05 commented Oct 3, 2024

Fixes #52

It introduces enhancements to the Landing component by applying a parallax effect to the coffee cup image. The key changes include:

  • Parallax Effect: The image moves slightly based on the mouse position, creating an engaging user experience. The translation effect is calculated to ensure smooth motion, enhancing the interactive feel of the landing page.

Changes Made:
Updated the parallaxEffect to combine both translation and rotation in the transform property of the motion.img element.
Ensured that the rotation does not interfere with the parallax effect, maintaining the visual consistency of the design.

Testing:

  • Verified the responsiveness and visual effect across different screen sizes and browsers.
  • Ensured no negative impact on existing functionalities or layouts.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced the landing page with interactive mouse tracking and animations.
    • Introduced a parallax effect for the coffee cup image that responds to mouse movements.
    • Added AOS animations for improved visual engagement.
  • Bug Fixes

    • Minor structural adjustments to improve the layout and remove unnecessary code.

Copy link

vercel bot commented Oct 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
play-cafe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 0:18am
play-cafe-bsbl ❌ Failed (Inspect) Oct 3, 2024 0:18am

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The changes in this pull request enhance the Landing component by incorporating mouse tracking and animation features. The useEffect hook is utilized to initialize AOS for scroll animations, while a new state variable tracks the mouse's coordinates, enabling a parallax effect on the coffee cup image. The component structure has been updated to include new dependencies and to improve interactivity through animations and visual enhancements.

Changes

File Change Summary
frontend/package.json - Added dependency "aos": "^2.3.4" to dependencies.
frontend/src/components/ui/Landing.jsx - Imported useEffect, motion, and AOS.
- Defined parallaxVariants and transition objects.
- Initialized AOS in useEffect.
- Introduced mousePosition state variable and handleMouseMove function.
- Implemented parallaxEffect for dynamic image movement.
- Modified coffee cup image to use motion.img for animations.
- Adjusted class names and structure, including margin changes and data attributes for AOS animations.

Assessment against linked issues

Objective Addressed Explanation
Add parallax mouse hover effect in home page (#52)

Possibly related PRs

Suggested labels

level 2, gssoc-ext

Suggested reviewers

  • RamakrushnaBiswal

Poem

🐰 In the land where the pixels play,
A coffee cup dances, bright as day.
With mouse in tow, it twirls and spins,
Bringing joy and laughter, where fun begins!
So hop along, let’s watch it glide,
In this animated world, let’s take a ride! ☕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Oct 3, 2024

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
frontend/src/components/ui/Landing.jsx (1)

Line range hint 56-78: Remove Unused Commented-Out Code

The block of commented-out code is no longer needed and can be removed to keep the codebase clean and maintainable.

Apply this diff to remove the unused code:

       <section className="flex flex-row justify-center items-center p-32" >
-        {/* <div className="w-3/5 p-28 mt-20">
-          <h1 className="text-8xl font-bold text-black ">
-            Our name says it all!
-          </h1>
-          <p className="text-black text-2xl">
-            Founder, Jonathan Li, shares a passion for board games, boba, and
-            delicious food, so he combined them all to become Sip & Play, Park
-            Slope’s first board game cafe. It is a straightforward concept: come
-            in with your friends and family to play any board game from our
-            library of 300+ games! We hope when you visit, you also enjoy our
-            coffee, espresso, boba, sandwiches, and snacks!
-          </p>
-          <ul className="text-xl mt-4">
-            <li>New opening hours:</li>
-            <li>Sunday: 10am-11pm</li>
-            <li>Mon-Thurs: 11am-11pm</li>
-            <li>Fri: 11am-midnight</li>
-            <li>Sat: 10am-midnight</li>
-          </ul>
-          <button className="p-2 border-2 border-slate-500">Learn more↗️</button>
-        </div> */}

Removing commented-out code improves readability and makes maintenance easier.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cbbda9b and 081baf6.

📒 Files selected for processing (1)
  • frontend/src/components/ui/Landing.jsx (3 hunks)

Comment on lines +26 to +31
const parallaxEffect = {
x: mousePosition.x / 100,
y: mousePosition.y / 100,


};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Adjust parallaxEffect Implementation for Correct Motion

The parallaxEffect object currently sets x and y properties based on the mouse position and applies them directly to the style prop of the motion.img. However, in Framer Motion, to animate positional properties like x and y, these should be motion values or controlled via the animate prop. Using plain numbers in the style prop won't produce the intended animation effect.

Consider using motion values or updating the animate prop to achieve the desired parallax effect. Here's how you can modify the code:

+import { useMotionValue, useTransform } from 'framer-motion';

...

+const x = useMotionValue(0);
+const y = useMotionValue(0);

...

 const handleMouseMove = (e) => {
-  const { clientX, clientY } = e;
-  setMousePosition({ x: clientX, y: clientY });
+  const { clientX, clientY } = e;
+  // Calculate the offset from the center of the screen
+  const offsetX = (clientX - window.innerWidth / 2) / 20;
+  const offsetY = (clientY - window.innerHeight / 2) / 20;
+  x.set(offsetX);
+  y.set(offsetY);
 };

-const parallaxEffect = {
-  x: mousePosition.x / 100,
-  y: mousePosition.y / 100,
-};

...

<motion.img
  src={coffecup}
  alt="Coffee Cup"
  className="cursor-pointer"
  variants={parallaxVariants}
  initial="initial"
  animate="animate"
  whileHover={{ scale: 1.1 }}
  transition={transition}
- style={parallaxEffect }
+ style={{ x, y }}
/>

This approach uses useMotionValue to create reactive x and y values that Framer Motion can animate efficiently.

Also applies to: 89-91

Comment on lines +21 to +24
const handleMouseMove = (e) => {
const { clientX, clientY } = e;
setMousePosition({ x: clientX, y: clientY });
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Throttle handleMouseMove for Improved Performance

Updating state on every mouse move event can lead to performance issues due to excessive re-renders. To optimize performance, consider throttling the handleMouseMove function.

You can use requestAnimationFrame to limit updates to once per animation frame:

+import { useRef } from 'react';

 export default function Landing() {

   const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
+  const animationFrame = useRef(null);
 
   const handleMouseMove = (e) => {
+    if (animationFrame.current === null) {
+      animationFrame.current = requestAnimationFrame(() => {
         const { clientX, clientY } = e;
         setMousePosition({ x: clientX, y: clientY });
+        animationFrame.current = null;
+      });
+    }
   };

This ensures that state updates occur at most once per frame, reducing the render load.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleMouseMove = (e) => {
const { clientX, clientY } = e;
setMousePosition({ x: clientX, y: clientY });
};
import { useRef } from 'react';
export default function Landing() {
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
const animationFrame = useRef(null);
const handleMouseMove = (e) => {
if (animationFrame.current === null) {
animationFrame.current = requestAnimationFrame(() => {
const { clientX, clientY } = e;
setMousePosition({ x: clientX, y: clientY });
animationFrame.current = null;
});
}
};

@RamakrushnaBiswal
Copy link
Owner

RamakrushnaBiswal commented Oct 3, 2024

@anshi05 can you some 3d type effect on it
or 1st the coffee cup will come whilw scrolling the texts will come

you can use aos.js

@anshi05
Copy link
Author

anshi05 commented Oct 5, 2024

Ok let me try if I can do that . Though I've never done that before.

@RamakrushnaBiswal
Copy link
Owner

@anshi05 sure

Copy link

vercel bot commented Oct 6, 2024

@anshi05 is attempting to deploy a commit to the bunty's projects Team on Vercel.

A member of the Team first needs to authorize it.

@anshi05
Copy link
Author

anshi05 commented Oct 6, 2024

I have added the fading animation to the text "PLAYCAFE". So now the coffee mug is visible and then the text comes on top of it after few seconds enhancing the overall user experience.

BoardGame.Cafe.-.Opera.2024-10-07.01-18-54.mp4

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
frontend/package.json (1)

15-15: LGTM! Consider adding AOS types for better development experience.

The addition of the AOS library (^2.3.4) aligns well with the PR objectives to implement scroll animations. This change is appropriately placed and maintains the alphabetical order of dependencies.

For improved TypeScript support and better IDE intellisense, consider adding the @types/aos package to your devDependencies. You can do this by running:

npm install --save-dev @types/aos

This will enhance the development experience when working with AOS in your TypeScript/JavaScript files.

frontend/src/components/ui/Landing.jsx (3)

87-99: Good progress on parallax effect, consider further optimization

The implementation of the coffee cup image with Framer Motion is a good step towards achieving the desired parallax effect. The use of animation variants, transitions, and hover effects enhances the user experience.

However, as mentioned in previous comments, consider optimizing the parallax effect by using motion values instead of directly applying the parallaxEffect to the style prop. This would result in smoother animations and better performance.

Refer to the earlier comments for detailed suggestions on implementing motion values for the parallax effect.


104-117: LGTM: AOS attributes for text animation

The addition of AOS attributes to the "PLAY" and "CAFE" text spans is a great way to enhance the visual appeal of the landing page. The use of different delays for each span creates a nice staggered animation effect.

Consider extracting the AOS-related className and data attributes into separate constants or a utility function to improve code readability and maintainability, especially if you plan to use similar animations elsewhere in the component.


Line range hint 1-122: Overall feedback: Good progress, with room for optimization

The changes in this PR significantly enhance the visual appeal and interactivity of the landing page, aligning well with the stated objectives. The implementation of the parallax effect, AOS animations, and Framer Motion contribute to a more engaging user experience.

However, there are opportunities for further optimization:

  1. Implement throttling for the mouse move handler to improve performance.
  2. Use Framer Motion's motion values for a smoother parallax effect.
  3. Consider extracting repeated animation attributes into constants or utility functions for better maintainability.

These optimizations will further improve the code quality and performance of the component. Great work on enhancing the landing page!

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 081baf6 and b37e1d5.

📒 Files selected for processing (2)
  • frontend/package.json (1 hunks)
  • frontend/src/components/ui/Landing.jsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (5)
frontend/src/components/ui/Landing.jsx (5)

1-17: LGTM: New imports and animation constants

The new imports and constants are well-structured and necessary for the implemented features. The use of framer-motion and AOS libraries aligns with the PR objectives of enhancing the visual appeal of the landing page.


20-25: LGTM: AOS initialization

The AOS library is correctly initialized using the useEffect hook. The settings are appropriate for achieving smooth scroll animations, and the hook is set to run only once on component mount, which is the correct approach.


42-42: LGTM: Improved section styling

The increased margin-bottom and addition of overflow-hidden improve the layout and prevent potential issues with content overflow. These changes contribute to a cleaner visual presentation of the landing page.


27-32: 🛠️ Refactor suggestion

Consider implementing throttling for mouse move handler

The mouse position tracking is implemented correctly. However, as mentioned in a previous review comment, consider implementing throttling for the handleMouseMove function to optimize performance. This will reduce the frequency of state updates and re-renders, especially during rapid mouse movements.


34-39: 🛠️ Refactor suggestion

Implement motion values for smooth parallax effect

As pointed out in a previous review comment, the current implementation of parallaxEffect may not produce the intended animation. Consider implementing motion values using Framer Motion's useMotionValue and useTransform hooks for a smoother parallax effect.

Refer to the previous comment for a detailed implementation suggestion using motion values.

Copy link
Contributor

This PR has been automatically closed due to inactivity from the owner for 3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Add Parallax Mouse hover effect in home page
2 participants